Posts

Post not yet marked as solved
3 Replies
890 Views
I have been searching for a reply to this problem for two days now.I have tried every single Google search result on the subject but I still can't get it working.Essentially, I want a single custom menu item to popup when I long press on a cell, but I want to handle the selector in the UITableViewController.I can get the selector to respond if I put everything in the cell but that wouldn't give me access to the list behind the table view.Over 50 people have viewed my previous post but not one reply. Surely this can't be that difficult?
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.1k Views
I need to popup a menu on a cell in a table view, but to respond to the action by specifying a selector on an object held elsewhere in the app.I have written the following code in the AppDelegate : let testMenuItem = UIMenuItem(title: "Test", action: #selector(ValueModelCellPresenter.test(sender:))) UIMenuController.shared.menuItems = [testMenuItem] UIMenuController.shared.update()I am implementing the shouldShowMenuForRowAt, canPerformAction and performAction methods on the table view delegate, as recommended, but the menu is not showing on long press.I have also implemented : public override var canBecomeFirstResponder: Bool { return true } public override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { return action == #selector(ValueModelCellPresenter.test(sender:)) } @objc public func test(sender: Any) { print("here") }… in the ValueModelCellPresenter class.I also tried calling becomeFirstResponder() on the presenter but to no avail.Can anyone please help me to see what I may have missed?
Posted Last updated
.
Post not yet marked as solved
1 Replies
922 Views
Greetings.I am creating a framework and making heavy use of generics; something I am well used to after many years of expreience in C#, before coming to Swift when it was first launched.I am getting an error on the declaration of the CommandSet class, which is proving difficult to resolve :"Type 'CommandSet<subjectT, commandIdentifierT, executionContextT, commandT>' does not conform to protocol 'NotifyCommandChanged'"This is accompanied by two "hints""Unable to infer associated type 'CommandType' for protocol 'NotifyCommandChanged'" on the declaration of the CommandType associatedtype in NotifyCommandChanged"Inferred type 'commandT' (by matching requirement 'commandChanged') is invalid: does not inherit from 'Command<Self.SubjectType, Self.IdentifierType, Self.ExecutionContextType>'" on the commandChanged lazy var in CommandSetI have been working on this for over a day now and would be very grateful if anyone out there can help me see what I am missing.public protocol StringEnumType : Hashable, RawRepresentable where Self.RawValue == String { } public protocol ExecutionContext { } open class Command<subjectt, identifiert="" :="" stringenumtype,="" executioncontextt="" executioncontext=""> { public var text: String? public func execute() { } } public protocol EventArgs { } public class Event<sendert, argst="" :="" eventargs=""> { private let sender: senderT public init(sender: senderT) { self.sender = sender } public func invoke(with args: argsT) { } } public struct CommandChangedEventArgs : EventArgs { public let commandIdentifier: identifierT public let keyPath: AnyKeyPath } public typealias CommandChangedEvent<subjectt, identifierT : StringEnumType, executionContextT : ExecutionContext, commandT : Command<subjectt, identifiert,="" executioncontextt="">> = Event<commandset<subjectt, identifiert,="" executioncontextt,="" commandt="">, CommandChangedEventArgs> public protocol NotifyCommandChanged { associatedtype SubjectType associatedtype IdentifierType : StringEnumType associatedtype ExecutionContextType : ExecutionContext associatedtype CommandType : Command<subjecttype, identifiertype,="" executioncontexttype=""> var commandChanged: CommandChangedEvent<subjecttype, identifiertype,="" executioncontexttype,="" commandtype=""> { get set } } open class CommandSet<subjectt, commandIdentifierT : StringEnumType, executionContextT : ExecutionContext, commandT : Command<subjectt, commandidentifiert,="" executioncontextt="">> : NotifyCommandChanged { private lazy var commands: [commandIdentifierT : commandT] = .init() public lazy var commandChanged: CommandChangedEvent<subjectt, commandidentifiert,="" executioncontextt,="" commandt=""> = .init(sender: self) }
Posted Last updated
.